import config from "@/config/index.config";

const apiUrlKey = 'api_url';
const signinUrlKey = 'signin_url';
const signalrUrlKey = 'signalr_url';
const fileUrlKey = 'file_url';
const uploadUrlKey = 'upload_url';

/**
 * 获取基本接口地址
*/
export function getApiUrl() {
	let currentUrl = uni.getStorageSync(apiUrlKey);
	// console.log(currentUrl);
	if(currentUrl === undefined || currentUrl === null || currentUrl === '' ){
		currentUrl = config.baseUrl;
	}
	return currentUrl;
};
/**
 * 设置基本接口地址
 * @param {String} baseUrl - 基本接口地址
*/
export function setApiUrl(baseUrl = '') {
	uni.setStorageSync(apiUrlKey, baseUrl);
};

/**
 * 获取第三方登录接口地址
*/
export function getSigninUrl() {
	let currentUrl = uni.getStorageSync(signinUrlKey);
	// console.log(currentUrl);
	if(currentUrl === undefined || currentUrl === null || currentUrl === '' ){
		currentUrl = config.baseUrl;
	}
	return currentUrl;
};
/**
 * 设置第三方登录接口地址
 * @param {String} baseUrl - 基本接口地址
*/
export function setSigninUrl(baseUrl = '') {
	uni.setStorageSync(signinUrlKey, baseUrl);
};

/**
 * 获取SignalR接口地址
*/
export function getSignalrUrl() {
	let currentUrl = uni.getStorageSync(signalrUrlKey);
	// console.log(currentUrl);
	if(currentUrl === undefined || currentUrl === null || currentUrl === '' ){
		currentUrl = config.baseUrl;
	}
	return currentUrl;
};
/**
 * 设置SignalR接口地址
 * @param {String} baseUrl - 基本接口地址
*/
export function setSignalrUrl(baseUrl = '') {
	uni.setStorageSync(signalrUrlKey, baseUrl);
};

/**
 * 获取静态资源映射地址
*/
export function getFileUrl() {
	let currentUrl = uni.getStorageSync(fileUrlKey);
	// console.log(currentUrl);
	if(currentUrl === undefined || currentUrl === null || currentUrl === '' ){
		currentUrl = config.baseUrl;
	}
	return currentUrl;
};
/**
 * 设置静态资源映射地址
 * @param {String} baseUrl - 基本接口地址
*/
export function setFileUrl(baseUrl = '') {
	uni.setStorageSync(fileUrlKey, baseUrl);
};

/**
 * 获取文件上传接口地址
*/
export function getUploadUrl() {
	let currentUrl = uni.getStorageSync(uploadUrlKey);
	// console.log(currentUrl);
	if(currentUrl === undefined || currentUrl === null || currentUrl === '' ){
		currentUrl = config.baseUrl;
	}
	return currentUrl;
};
/**
 * 设置文件上传接口地址
 * @param {String} baseUrl - 基本接口地址
*/
export function setUploadUrl(baseUrl = '') {
	uni.setStorageSync(uploadUrlKey, baseUrl);
};
